# -*- coding:utf-8 -*-

from flask import Flask,render_template,session,redirect,url_for,request,flash
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField,SelectField,TextAreaField
from wtforms.validators import Required, Length, Email, Regexp, EqualTo, DataRequired
from flask_bootstrap import Bootstrap
from flask_script import Manager

app = Flask(__name__)
app.config['SECRET_KEY']='hard to guess string'

manager = Manager(app)
bootstrap = Bootstrap(app)

# 用户登录表单
class LoginForm(FlaskForm):
    uname = StringField(u'用户名：', validators=[
        DataRequired(), Length(1,32), '^[A-Za-z][A-Za-z0-9_.]*$', 0, u'用户名必须由字母、数字、下划线或 . 组成'])
    pwd = PasswordField(u'密码：', validators=[DataRequired()])
    remember_me = BooleanField(u'记住我？')

    submit = SubmitField(u'登录')
    # test = StringField(u'测试：', validators=[DataRequired()])
    # email = StringField('Email', validators=[Required(), Length(1, 64),
    #                                          Email()])
    # username = StringField('Username', validators=[
    #     Required(), Length(1, 64), Regexp('^[A-Za-z][A-Za-z0-9_.]*$', 0,
    #                                       'Usernames must have only letters, '
    #                                       'numbers, dots or underscores')])
    # confirmed = BooleanField('Confirmed')
    # # role = SelectField('Role', coerce=int)
    # name = StringField('Real name', validators=[Length(0, 64)])
    # location = StringField('Location', validators=[Length(0, 64)])
    # about_me = TextAreaField('About me')
    # submit2 = SubmitField('Submit')



@app.route('/')
def index():
    form = LoginForm()
    return render_template('login3_modify.html',form=form)

@app.route('/submit',methods=['GET','POST'])
def submit():
    form = LoginForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # username = form.data['Username']
            # print username
            flash('test')
        # return 'test'
    else:
        return render_template('login3_modify.html',form = form)


if __name__ == '__main__':
    app.run(debug=True)